<?php
/**
 * Created by PhpStorm.
 * User: Qarluq
 * Date: 15/6/24
 * Time: 下午5:24
 */
class Category {
    static function unlimitedforlevel($cate,$html='----',$pid=0,$level=0){

        $arr=array();
        foreach($cate as $v){
             if($v['pid']==$pid){
                $v['level']=$level+1;
                $v['html']=str_repeat($html,$level);
                $arr[]=$v;
                $arr=array_merge($arr,self::unlimitedforlevel($cate,$html,$v['id'],$level+1));
            }
        }
        return $arr;
    }
    /*
     *
     * */
    static function unlimitedforlayer($cate,$name='child',$pid=0){
        $arr=array();
        foreach($cate as $v){
            if($v['pid']==$pid){
                $v[$name]=self::unlimitedforlayer($cate,$name,$v['id']);
                $arr[]=$v;
            }
        }
        return $arr;
    }
    /*
     *
     * */
    static function getparents($cate,$id){
        $arr=array();
        foreach($cate as $v){
            if($v['id']==$id){
                $arr[]=$v;
                $arr=array_merge(self::getparents($cate,$v['pid']),$arr);
            }
        }
             return $arr;
    }

    /*
     *
     * */
    static function getchildsid($cate,$id){
        $arr=array();
        foreach($cate as $v){
            if($v['pid']==$id){
                $arr[]=$v;
               $arr= array_merge(self::getchildsid($cate,$v['id']),$arr);
            }
        }
             return $arr;
    }
     /*
     *
     * */
    static function getchilds($cate,$pid){
        $arr=array();
        foreach($cate as $v){
            if($v['pid']==$pid){
                $arr[]=$v;
                $arr=array_merge($arr,self::getchilds($cate,$v['id']));
            }
        }
             return $arr;
    }

}